package com.itheima.exception;

import com.itheima.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(RuntimeException.class)
    public Result<?> error(RuntimeException exception){
        log.error(exception.getMessage(),exception);
        return Result.error(exception.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public Result<?> error(Exception exception){
        log.error(exception.getMessage(),exception);
        return Result.error("系统正在繁忙");
    }

}
